<%--
  Created by IntelliJ IDEA.
  User: landeqing
  Date: 2018/1/28
  Time: 0:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript" src="/jquery/jquery-3.2.1.min.js"></script>
<html>
<head>
    <title>商品列表</title>
    <script type="text/javascript" language="JavaScript">
        function queryByName() {
           var productName=$(".productName").val();
           var typeId=$(".typeId").val();
           window.location.href="/product/productList?productName="+encodeURI(encodeURI(productName))+"&productTypeId="+typeId;
        }
        function resetTable() {
            var typeId=$(".typeId").val();
            window.location.href="/product/productList?productTypeId="+typeId;
        }
        function toUpdate(id) {
           window.location.href="/product/toUpdate?id="+id;
        }
        function   deleteProduct(id){
            var typeId=$(".typeId").val();
            window.location.href="/product/delete?id="+id+"&typeId="+typeId;
        }
        $(document).ready(function(){
            //加的效果
            $(".add").click(function(){
                var n=$(this).prev().val();
                var num=parseInt(n)+1;
                if(num==0){ return;}
                $(this).prev().val(num);
            });
            //减的效果
            $(".jian").click(function(){
                var n=$(this).next().val();
                var num=parseInt(n)-1;
                if(num==0){ return}
                $(this).next().val(num);
            });
        })
        function addCart(id) {
            $("#productId").val(id);
            var count=$(".num").val();
            $(".count").val(count);
            var uid='${sessionScope.user.id}';
            if (uid!=null&&uid!="") {
                $("#cartForm").submit();
            }else{
                alert("请先登录");
                window.location.href="/user/toLogin";
            }
       }
    </script>
    <style type="text/css">
        .gw_num {
            border: 1px solid #dbdbdb;
            width: 100px;
            line-height: 26px;
            overflow: hidden;
        }

        .gw_num em {
            display: block;
            height: 15px;
            width: 16px;
            float: left;
            color: #7A7979;
            border-right: 1px solid #dbdbdb;
            text-align: center;
            cursor: pointer;
        }

        .gw_num .num {
            display: block;
            float: left;
            text-align: center;
            width: 60px;
            font-style: normal;
            font-size: 14px;
            line-height: 24px;
            border: 0;
        }

        .gw_num em.add {
            float: right;
            border-right: 0;
            border-left: 1px solid #dbdbdb;
        }
    </style>
</head>
<body>
<form method="post">
    <table border="1">
        <div>
            <tr>
                <td><input type="text" name="productName" class="productName" value="${strProductName}">&nbsp;&nbsp;
                    <input type="button" value="查询" onclick="queryByName()">&nbsp;&nbsp;
                    <input type="button" value="重置" onclick="resetTable()" >
                </td>
            </tr>
        </div>
        <div>
            <tr>
                <td>商品编号</td>
                <td>商品名称</td>
                <td>商品价格</td>
                <td>商品尺寸</td>
                <td>分辨率</td>
                <td>商品产地</td>
                <td>商品类型</td>
                <td>操作</td>
            </tr>
            <c:forEach items="${voList}" var="obj">
                <tr>
                    <td>${obj.id}</td>
                    <td>${obj.product_name}</td>
                    <td>${obj.price}</td>
                    <td>${obj.size}</td>
                    <td>${obj.resolution}</td>
                    <td>${obj.place}</td>
                    <td>${obj.productTypeName}</td>
                    <input type="hidden" value="${obj.type_id}" class="typeId">
                    <td><input type="button" value="编辑" onclick="toUpdate(${obj.id})">&nbsp;&nbsp;
                        <input type="button" value="删除" onclick="deleteProduct(${obj.id})"> &nbsp;&nbsp;
                         <div class="gw_num">
                            <em class="jian">-</em>
                            <input type="text" value="1" class="num" name="count"/>
                            <em class="add">+</em>
                        </div>&nbsp;&nbsp;
                        <input type="button" value="加入购物车" onclick="addCart(${obj.id})"></td>&nbsp;&nbsp;
                </tr>
            </c:forEach>
        </div>
    </table>
</form>
<form method="post" action="/shoppingCart/save" id="cartForm">
    <input type="hidden" name="productId" id="productId">
    <input type="hidden" name="uID" value="${sessionScope.user.id}">
    <input type="hidden" name="id">
    <input type="hidden" name="status" value="0">
    <input type="hidden"  class="count" name="count"/>
    <a href="/shoppingCart/list?uid=${sessionScope.user.id}">查看购物车</a>
</form>
</body>
</html>
